﻿using System;

namespace GenericityDispatch
{
    /// <summary>
    /// 反射类的信息
    /// </summary>
    public class ReflectionClassInfo
    {
        /// <summary>
        /// 节点序号
        /// </summary>
        public int Index { get; set; }
        /// <summary>
        /// 类的类型
        /// </summary>
        public Type ClassType { get; set; }

        /// <summary>
        /// 通过类创建的对象
        /// </summary>
        public object ClassObj => Activator.CreateInstance(ClassType);

        /// <summary>
        /// 获取父类
        /// </summary>
        public Type BaseType => ClassType?.BaseType;

        /// <summary>
        /// 获取父类泛型参数
        /// </summary>
        public Type[] GenericArguments => ClassType?.BaseType?.GetGenericArguments();

        /// <summary>
        /// 创建对象 
        /// </summary>
        /// <param name="classType"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static ReflectionClassInfo CreateInstance(Type classType, int index)
        {
            return new ReflectionClassInfo()
            {
                ClassType = classType,
                Index = index
            };
        }
    }
}
